
export const useRouterConfig = () => {
  const resolveComponent = (path) => {
    const modules = import.meta.glob("./views/**");
    // console.log(modules);
    // console.log(path);
    // 拿到views下面的所有文件之后，动态拼接`key`去获取value
    const importPage = modules[`./views${path}`];
    if (!importPage) {
      throw new Error(
        `Unknown page ${path}. Is it located under Pages with a .vue extension?`
      );
    }
    return importPage;
  };
  const  makeMenuRoute = (routesArray)=> {
    const routeArray = [];
    routesArray.forEach((item) => {
      const route = {
        id: item.id,
        pid: item.pid,
        children: [],
        path:  item.code.replace('.vue',''),
        name: item.name,
        component: "",
        meta: {
          title: item.name,
          icon: item.icon?item.icon:'Platform',
          type: "",
        },
      };
      if (item.code === "/" ||!item.code.includes('.vue')) {
        //Layout组件特殊处理
        route.component = import("@/views/Main/index.vue");
        if(item.code==='/home')  route.component =import("@/views/Home/index.vue");
      } else {
        route.component = resolveComponent(item.code);
      }
      routeArray.push(route);
    });
    return routeArray;
  }
  return { makeMenuRoute,resolveComponent };
};

